package refactortips.editors.codeSmells;

import org.eclipse.swt.SWT;
import org.eclipse.swt.browser.Browser;
import org.eclipse.swt.custom.ScrolledComposite;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Link;
import org.eclipse.swt.widgets.TabFolder;
import org.eclipse.swt.widgets.TabItem;
import org.eclipse.ui.forms.widgets.Form;
import org.eclipse.ui.forms.widgets.FormToolkit;
import org.eclipse.wb.swt.SWTResourceManager;

import refactortips.editors.AbstractRefactorTipsEditor;
import refactortips.editors.CommandMouseAdapter;

import org.eclipse.wb.swt.ResourceManager;

public class SwitchStatementsEditor extends AbstractRefactorTipsEditor {

	protected final FormToolkit formToolkit = new FormToolkit(Display.getDefault());
	
	public SwitchStatementsEditor() {
	}

	/**
	 * Create contents of the editor part.
	 * @param parent
	 */
	@Override
	public void createPartControl(Composite parent) {
		
		Form frmCodeSmell = formToolkit.createForm(parent);
		formToolkit.paintBordersFor(frmCodeSmell);
		frmCodeSmell.setText("Switch Statements");
		frmCodeSmell.getBody().setLayout(new FillLayout(SWT.HORIZONTAL));
		
		TabFolder tabFolder = new TabFolder(frmCodeSmell.getBody(), SWT.NONE);
		formToolkit.adapt(tabFolder);
		formToolkit.paintBordersFor(tabFolder);
		
		ScrolledComposite sc = new ScrolledComposite(tabFolder, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
		sc.setExpandHorizontal(true);
	    sc.setExpandVertical(true);
		
		TabItem tbtmDescription = new TabItem(tabFolder, SWT.NONE);
		tbtmDescription.setText("Descri\u00E7\u00E3o");
		
		ScrolledComposite scrolledComposite = new ScrolledComposite(tabFolder, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
		tbtmDescription.setControl(scrolledComposite);
		formToolkit.paintBordersFor(scrolledComposite);
		scrolledComposite.setExpandHorizontal(true);
		scrolledComposite.setExpandVertical(true);
		
		Composite composite_3 = new Composite(scrolledComposite, SWT.NONE);
		formToolkit.adapt(composite_3);
		formToolkit.paintBordersFor(composite_3);
		composite_3.setLayout(null);
		
		Label lblDescription = new Label(composite_3, SWT.NONE);
		lblDescription.setBounds(10, 10, 102, 25);
		lblDescription.setForeground(SWTResourceManager.getColor(SWT.COLOR_BLACK));
		lblDescription.setFont(SWTResourceManager.getFont("Segoe UI", 14, SWT.BOLD));
		formToolkit.adapt(lblDescription, true, true);
		lblDescription.setText("Descri\u00E7\u00E3o");
		
		Label label = new Label(composite_3, SWT.NONE);
		label.setImage(ResourceManager.getPluginImage("RefactorTips", "images/codeSmells/switchStatements.jpg"));
		label.setBounds(43, 66, 400, 480);
		formToolkit.adapt(label, true, true);
		
		Link linkExtractMethod1 = new Link(composite_3, SWT.NONE);
		linkExtractMethod1.setBounds(516, 379, 104, 21);
		linkExtractMethod1.setFont(SWTResourceManager.getFont("Segoe UI", 12, SWT.NORMAL));
		linkExtractMethod1.addMouseListener(new CommandMouseAdapter(getSite(), "RefactorTips.commands.extractMethodCommand"));
		formToolkit.adapt(linkExtractMethod1, true, true);
		linkExtractMethod1.setText("<a>Extract Method</a>");
		
		Link linkMoveMethod = new Link(composite_3, 0);
		linkMoveMethod.setText("<a>Move Method</a>");
		linkMoveMethod.setFont(SWTResourceManager.getFont("Segoe UI", 12, SWT.NORMAL));
		linkMoveMethod.setBounds(544, 401, 104, 21);
		formToolkit.adapt(linkMoveMethod, true, true);
		
		Link linkReplaceTypeCodeWithSubclasses = new Link(composite_3, 0);
		linkReplaceTypeCodeWithSubclasses.setText("<a>Replace Type Code with Subclasses</a>");
		linkReplaceTypeCodeWithSubclasses.setFont(SWTResourceManager.getFont("Segoe UI", 12, SWT.NORMAL));
		linkReplaceTypeCodeWithSubclasses.setBounds(609, 443, 244, 21);
		formToolkit.adapt(linkReplaceTypeCodeWithSubclasses, true, true);
		
		Link linkReplaceTypeCodeWithStateStrategy = new Link(composite_3, 0);
		linkReplaceTypeCodeWithStateStrategy.setText("<a>Replace Type Code with State/Strategy</a>");
		linkReplaceTypeCodeWithStateStrategy.setFont(SWTResourceManager.getFont("Segoe UI", 12, SWT.NORMAL));
		linkReplaceTypeCodeWithStateStrategy.setBounds(471, 462, 268, 21);
		formToolkit.adapt(linkReplaceTypeCodeWithStateStrategy, true, true);
		
		Link linkReplaceConditionalWithPolymorphism = new Link(composite_3, 0);
		linkReplaceConditionalWithPolymorphism.setText("<a>Replace Conditional with Polymorphism</a>.");
		linkReplaceConditionalWithPolymorphism.setFont(SWTResourceManager.getFont("Segoe UI", 12, SWT.NORMAL));
		linkReplaceConditionalWithPolymorphism.setBounds(486, 507, 281, 21);
		formToolkit.adapt(linkReplaceConditionalWithPolymorphism, true, true);
		
		Link linkReplaceParameterWithExplicitMethods = new Link(composite_3, 0);
		linkReplaceParameterWithExplicitMethods.setText("<a>Replace Parameter with Explicit Methods</a>");
		linkReplaceParameterWithExplicitMethods.setFont(SWTResourceManager.getFont("Segoe UI", 12, SWT.NORMAL));
		linkReplaceParameterWithExplicitMethods.setBounds(304, 579, 281, 21);
		formToolkit.adapt(linkReplaceParameterWithExplicitMethods, true, true);
		
		Link linkIntroduceNullObject = new Link(composite_3, 0);
		linkIntroduceNullObject.setText("<a>Introduce Null Object</a>");
		linkIntroduceNullObject.setFont(SWTResourceManager.getFont("Segoe UI", 12, SWT.NORMAL));
		linkIntroduceNullObject.setBounds(263, 599, 148, 21);
		formToolkit.adapt(linkIntroduceNullObject, true, true);
		
		StyledText styledText = new StyledText(composite_3, SWT.READ_ONLY | SWT.WRAP);
		styledText.setEnabled(false);
		styledText.setDoubleClickEnabled(false);
		styledText.setJustify(true);
		styledText.setFont(SWTResourceManager.getFont("Segoe UI", 12, SWT.NORMAL));
		styledText.setText("\t\tUm dos sintomas mais \u00F3bvios de c\u00F3digo orientado a objeto \u00E9 a sua falta de instru\u00E7\u00F5es switch. O problema com instru\u00E7\u00F5es switch \u00E9 essencialmente duplica\u00E7\u00E3o. Normalmente voc\u00EA encontra a mesma express\u00E3o switch espalhada pelo c\u00F3digo em diferentes lugares. Se voc\u00EA adicionar uma nova cl\u00E1usula ao switch, voc\u00EA precisa encontrar todos esses switches, express\u00F5es e alter\u00E1-los. A no\u00E7\u00E3o orientada a objeto de polimorfismo lhe d\u00E1 uma forma elegante para lidar com esse problema.");
		styledText.setBounds(486, 61, 435, 207);
		formToolkit.adapt(styledText);
		formToolkit.paintBordersFor(styledText);
		
		StyledText styledText_1 = new StyledText(composite_3, SWT.READ_ONLY | SWT.WRAP);
		styledText_1.setText("\t\tA maioria das vezes que voc\u00EA v\u00EA uma express\u00E3o switch voc\u00EA deve considerar polimorfismo. O problema \u00E9 onde o polimorfismo deve ocorrer. Normalmente a express\u00E3o switch alterna sobre o tipo de c\u00F3digo. Voc\u00EA quer que o m\u00E9todo ou classe que abriga o valor do c\u00F3digo do tipo. Ent\u00E3o use\t\t\t\t\t\t\tpara extrair a express\u00E3o switch e ent\u00E3o\t\t\t\t\t\t\tpara obt\u00EA-la na classe onde o polimorfismo \u00E9 necess\u00E1rio. Nesse ponto voc\u00EA deve decidir se voc\u00EA ir\u00E1\t\t\t\t\t\t\t\t\tou \t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t. Quando voc\u00EA organizar a estrutura de heran\u00E7a, voc\u00EA pode usar");
		styledText_1.setJustify(true);
		styledText_1.setFont(SWTResourceManager.getFont("Segoe UI", 12, SWT.NORMAL));
		styledText_1.setEnabled(false);
		styledText_1.setDoubleClickEnabled(false);
		styledText_1.setBounds(486, 274, 435, 260);
		formToolkit.adapt(styledText_1);
		formToolkit.paintBordersFor(styledText_1);
		
		StyledText styledText_2 = new StyledText(composite_3, SWT.READ_ONLY | SWT.WRAP);
		styledText_2.setText("\t\tSe voc\u00EA apenas tiver alguns casos que afetam um \u00FAnico m\u00E9todo, e voc\u00EA n\u00E3o espera que eles mudem, ent\u00E3o polimorfismo \u00E9 um \u201Ctiro de bazuca\u201D. Nesse caso\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\u00E9 uma boa op\u00E7\u00E3o. Se um dos seus casos condicionais for um null, tente\t\t\t\t\t\t\t\t\t\t\t.");
		styledText_2.setJustify(true);
		styledText_2.setFont(SWTResourceManager.getFont("Segoe UI", 12, SWT.NORMAL));
		styledText_2.setEnabled(false);
		styledText_2.setDoubleClickEnabled(false);
		styledText_2.setBounds(43, 558, 878, 100);
		formToolkit.adapt(styledText_2);
		formToolkit.paintBordersFor(styledText_2);
		scrolledComposite.setContent(composite_3);
		scrolledComposite.setMinSize(composite_3.computeSize(SWT.DEFAULT, SWT.DEFAULT));
		
		TabItem tbtmUsage = new TabItem(tabFolder, SWT.NONE);
		tbtmUsage.setText("Exemplo");
		
		ScrolledComposite scrolledComposite_1 = new ScrolledComposite(tabFolder, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
		tbtmUsage.setControl(scrolledComposite_1);
		formToolkit.paintBordersFor(scrolledComposite_1);
		scrolledComposite_1.setExpandHorizontal(true);
		scrolledComposite_1.setExpandVertical(true);
		
		Composite composite = new Composite(scrolledComposite_1, SWT.NONE);
		formToolkit.adapt(composite);
		formToolkit.paintBordersFor(composite);
		scrolledComposite_1.setContent(composite);
		scrolledComposite_1.setMinSize(composite.computeSize(SWT.DEFAULT, SWT.DEFAULT));
		
		TabItem tbtmVideo = new TabItem(tabFolder, SWT.NONE);
		tbtmVideo.setText("Video");
		
		Browser browser = new Browser(tabFolder, SWT.NONE);
		browser.setUrl("");
		tbtmVideo.setControl(browser);
		formToolkit.paintBordersFor(browser);
	}
}
